import Graphin from '@antv/graphin';
import iconLoader from '@antv/graphin-icons';

const { fontFamily } = iconLoader();
const icons = Graphin.registerFontFamily(iconLoader);

const parser = (data) => {
  let { nodes, links: edges } = data;
  const nodeParser = (node) => {
    return {
      id: node.id,
      style: {
        label: {
          value: node.name,
        },
        icon: {
          fontFamily,
          type: 'font',
          value: icons.company,
          fillOpacity: 0.8,
          fill: node.type === 'listedCompany' ? 'red' : '#3da2ff',
          stroke: node.type === 'listedCompany' ? 'red' : '#3da2ff',
          size: 20,
        },
        keyshape: {
          size: 32,
          fill: node.type === 'listedCompany' ? 'red' : '#3da2ff',
          stroke: node.type === 'listedCompany' ? 'red' : '#3da2ff',
        },
      },
    };
  };
  const edgeParser = (edge) => {
    return {
      id: edge.id,
      source: edge.source,
      target: edge.target,
      style: {
        label: {
          value: edge.type,
          fill: 'red',
        },
        keyshape: {
          stroke: '#999999',
          // lineWidth: 4,
        },
      },
    };
  };
  nodes = nodes.map((node) => nodeParser(node));
  edges = edges.map((edge) => edgeParser(edge));
  return {
    nodes,
    edges,
  };
};

export default parser;
